//
//  User.swift
//  AppArchitectureSwift
//
//  Created by 胡锦涛 on 2019/2/20.
//  Copyright © 2019 胡锦涛. All rights reserved.
//

import UIKit
import ObjectMapper

class User: BaseModel {
    
    ///名字
    var name: String = ""
    
    ///图片
    var imageUrl: String = ""
    
    ///年龄
    var age: String = ""
    
    
    override func mapping(map: Map) {
        super.mapping(map: map)
        name                       <-       map["name"]
        imageUrl                   <-       map["imageUrl"]
        age                        <-       map["age"]
    }
    ///获取数据
    static func getUsers(usersBlock: @escaping (_ users:[ User])-> Void){
        //获取数据
        var tempArr: [Any] = [["name":"Steven","imageUrl":"http://cc","age":"19"],
                   ["name":"Bob","imageUrl":"http://cc","age":"18"],
                   ["name":"Paul","imageUrl":"http://cc","age":"17"],
                   ["name":"Lucy","imageUrl":"http://cc","age":"99"]]
        var userDatas:[User] = [User]()
        for i in 0..<tempArr.count  {
            let user:User = Mapper<User>().map(JSONObject: tempArr[i])!
            //添加到数组中
            userDatas.append(user)
            
        }
        
        //GCD设置延迟
        HKDelay(0.25) {
            usersBlock(userDatas)
        }
        
    }
    
    
}
